package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.User;

/**
 * Servlet implementation class LoginServlet
 */
public class LoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public LoginServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		String info="ç™»å½•é”™è¯¯";
//		String uname=request.getParameter("uname");
//		String psd=request.getParameter("psd");
//		if("john".equals(uname)&&"123".equals(psd)){
//			User u=new User();
//			u.setAge(2);u.setUname(uname);u.setAge(100);
//			request.getSession().setAttribute("u", u);
//			info="ç™»å½•æˆ�åŠŸ";
//		}
//		response.setContentType("text/html;charset=UTF-8");
//		PrintWriter writer=response.getWriter();
//		writer.write(info);
//		writer.close();
		
		String info = "登录失败";
		
		String uname = request.getParameter("uname");
		String pwd = request.getParameter("pwd");
		
		if("jordan".equals(uname)){
			info = "登录成功";
			User u = new User();
			u.setAge(11);
			u.setId(1);
			u.setUname("jordan");
			
			request.getSession().setAttribute("u", u);
		}
		
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter writer = response.getWriter();
		writer.write(info);
		writer.close();
	}

}

















